/**
 * 商户分润查询
 */
function getUserProfit(){
	formSubmitForAjax({
		data : {},
		url: BASE_PATH + "myProfit.web",
		success : showUserProfit
	});
}
/**
 * 根据查询到的商户分润信息在页面展示
 * @param json
 * @returns {Boolean}
 */
function showUserProfit(json){
	if(!codeSuccess(json)){
		alert("收益查询失败！");
		return false;
	}
	
	var profitList = json["profitList"];
	if(!profitList){
		return false;
	}
	var profit = {};
	for (var i = 0; i < profitList.length; i++) {
		profit = profitList[i];
		var sharStatus = profit["sharStatus"];
		var $profitBox = {};
		if(!sharStatus){
			$profitBox = $("#sharStatus_sum");
		}else{
			$profitBox = $("#sharStatus_" + sharStatus);
		}
		
		//填充参数
		fillTable($profitBox, profit);
		$profitBox.show();
	}
	
}

/**
 * 处理未提现分润项,如果未提现金额大于零,则显示提现按钮
 * @param amt
 * @returns {String}
 */
function profitCas(amt){
	var html = amt + "元";
	if(amt > 0){//有未提分润金额,则显示提现按钮
		html += '<button class="btn btn-sm btn-primary" id="casBtn" onclick="casProfitSubmit()">提现</button>';
	}
	return html;
}

/**
 * 提交提现申请
 */
function casProfitSubmit(){
	var r = confirm("您确定要发起提现申请吗？");
	if (r == false) {
		return;
	}
	formSubmitForAjax({
		data : {},
		url: BASE_PATH + "profitCas.web",
		success : casSuccess
	});
}

/**
 * 提交提现申请响应成功
 * @param json
 */
function casSuccess(json){
	alert(json["RSPMSG"]);
	//刷新分润显示
	getUserProfit();
}

//加载完成执行
$(document).ready(function() {
	getUserProfit();
});